package com.tianhao.luo.lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 验证ReentrantLock是可重入锁
 *
 * @author tianhao.luo@hand-china.com
 */
public class ReentrantLockDemo {

    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();

        new Thread(()->{
            lock.lock();
            try {
                System.out.println(Thread.currentThread().getName()+" a");
                lock.lock();
                try {
                    System.out.println(Thread.currentThread().getName()+" b");

                }finally {
                    lock.unlock();
                }
            }finally {
                lock.unlock();
            }
        }).start();
    }
}
